/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import controller.cCheckerboard;
import error.ConfirmationDialog;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
/**
 *
 * @author Robert
 */
public class UserOption extends JPanel implements ActionListener{

    private iDraughts mainFrame;            // Contains everything
    private JButton surrenderButton;        // Button used to surrender
    private JButton newGame;                // Button to begin a new game
    private cCheckerboard checkerboard;
    private JLabel labelPlayer;             // Show which player is currently playing
    private JLabel labelNbPieceLeftP1;        // Show number of pieces left for Player1
    private JLabel labelNbPieceLeftP2;        // Show number of pieces left for Player2
    public UserOption(cCheckerboard cb, iDraughts mF){

        mainFrame = mF;
        checkerboard = cb;
        JPanel mainPanel = new JPanel();
        mainPanel.setLocation(500, 0);
        mainPanel.setSize(300, 500);
        mainPanel.setBackground(Color.lightGray);


        // First panel on top
        // Contains information : player's turn, number of pieces in game...
        JPanel panelPlayer = new JPanel();
        panelPlayer.setLayout(null);
        Dimension d = new Dimension();
        d.setSize(300, 350);
        panelPlayer.setPreferredSize(d);
        panelPlayer.setBackground(Color.lightGray);
        Border borderColor = BorderFactory.createLineBorder(Color.black, 2);
        panelPlayer.setBorder(borderColor);


        locateLabelPlayer(panelPlayer);
        locateLabelNbPiecesLeft(panelPlayer);
        
        surrenderButton = new JButton("Abandonner");
        newGame = new JButton("Nouvelle Partie");

        //Events on click
        surrenderButton.addActionListener(this);
        newGame.addActionListener(this);

        // Add everything in the main Frame
        mainPanel.add(panelPlayer);
        mainPanel.add(newGame);
        mainPanel.add(surrenderButton);
        mainFrame.add(mainPanel);
    }

    public void actionPerformed(ActionEvent e) {
        ConfirmationDialog cd;
        if(e.getActionCommand().equals("Nouvelle Partie"))
            cd = new ConfirmationDialog("Nouvelle partie", "Voulez vous commencer une nouvelle partie ?", mainFrame, checkerboard, 0);
        else if(e.getActionCommand().equals("Abandonner"))
            cd = new ConfirmationDialog("Abandonner", "Voulez vous vraiment abandonner ?", mainFrame, checkerboard, 1);
    }


    /**
     * @param labelPlayer the labelPlayer to set
     */
    public void setLabelPlayer(String labelPlayer) {
        this.labelPlayer.setText("Tour du joueur : " +labelPlayer);
    }

    /**
     * @param labelNbPieceLeft the labelNbPieceLeft to set
     */
    public void setLabelNbPieceLeftP1(String labelNbPieceLeft) {
        this.labelNbPieceLeftP1.setText("Joueur 1 : " + labelNbPieceLeft);
    }

    /**
     * @param labelNbPieceLeft the labelNbPieceLeft to set
     */
    public void setLabelNbPieceLeftP2(String labelNbPieceLeft) {
        this.labelNbPieceLeftP2.setText("Joueur 2 : " + labelNbPieceLeft);
    }

    public void locateLabelPlayer(JPanel panelPlayer){
        // Panel containing labelPlayer
        JPanel playerPanel = new JPanel();
        playerPanel.setLayout(null);
        playerPanel.setLocation(100, 200);
        playerPanel.setSize(200, 50);
        playerPanel.setBackground(Color.lightGray);
        panelPlayer.add(playerPanel);

        // Add Label
        labelPlayer = new JLabel("Tour du joueur : 1");
        labelPlayer.setLocation(0, 0);
        labelPlayer.setSize(110, 20);
        labelPlayer.setHorizontalAlignment(0);
        playerPanel.add(labelPlayer);
    }

    public void locateLabelNbPiecesLeft(JPanel panelPlayer){
        
        // Panel containing labelNbPieces
        JPanel panelNbPieceLeft = new JPanel();
        panelNbPieceLeft.setLayout(null);
        panelNbPieceLeft.setLocation(30, 4);
        panelNbPieceLeft.setSize(300, 200);
        panelNbPieceLeft.setBackground(Color.lightGray);
        panelPlayer.add(panelNbPieceLeft);

        // Add picture P1
        JLabel imageP1 = new JLabel( new ImageIcon("../jdd/src/img/black_pawn1.png"));
        imageP1.setLocation(100, 10);
        imageP1.setSize(50, 50);
        imageP1.setHorizontalAlignment(0);

        // Add Label P1
        labelNbPieceLeftP1 = new JLabel("Joueur 1 : 20");
        labelNbPieceLeftP1.setLocation(30, 55);
        labelNbPieceLeftP1.setSize(180, 20);
        labelNbPieceLeftP1.setHorizontalAlignment(0);

        // Add picture
        JLabel imageP2 = new JLabel( new ImageIcon("../jdd/src/img/red_pawn1.png"));
        imageP2.setLocation(100, 100);
        imageP2.setSize(50, 50);
        imageP2.setHorizontalAlignment(0);

        // Add Label P2
        labelNbPieceLeftP2 = new JLabel("Joueur 2 : 20");
        labelNbPieceLeftP2.setLocation(30, 160);
        labelNbPieceLeftP2.setSize(180, 20);
        labelNbPieceLeftP2.setHorizontalAlignment(0);


        panelNbPieceLeft.add(imageP1);
        panelNbPieceLeft.add(imageP2);
        panelNbPieceLeft.add(labelNbPieceLeftP1);
        panelNbPieceLeft.add(labelNbPieceLeftP2);
        
    }
}
